package me.zhengjie.tool;


import java.math.BigDecimal;
import java.util.List;


public class Condition {

	private String operator;

	private String columnName;

	private String columnValue;


	public String getOperator() {
		return operator;
	}


	public void setOperator(String operator) {
		this.operator = operator;
	}


	public String getColumnName() {
		return columnName;
	}


	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}


	public String getColumnValue() {
		return columnValue;
	}


	public void setColumnValue(String columnValue) {
		this.columnValue = columnValue;
	}


	public Condition(String operator, String columnName, String columnValue) {
		super();
		this.operator = operator;
		this.columnName = columnName;
		this.columnValue = columnValue;
	}


	public Condition() {
		super();
	}


	public BigDecimal getcolumnValueAsBigDecimal(){
		return new BigDecimal(getColumnValue());
	}


	/**
	 * 获取SQL条件字符串
	 * 注：
	 * 1. 使用AND关联列表条件
	 * 2. 不支持没有WHERE的情况
	 * @param conditions
	 * @return
	 */
	public static String toSqlConditionString(List<Condition> conditions){
		StringBuffer sqlConditionString = new StringBuffer();
		if(!ValidateUtil.isEmpty(conditions)) {
			for (Condition condition : conditions) {
				sqlConditionString.append(" AND ").append(condition.getColumnName()).append(" ")
						.append(condition.getOperator()).append(" ")
						.append(condition.getColumnValue());
			}
		}
		return ValidateUtil.isEmpty(sqlConditionString)? "":sqlConditionString.toString();
	}

//	public static void main(String[] args) {
//		List<Condition> list = new ArrayList();
//		Condition condition1 = new Condition(">","aae041","201801");
//		Condition condition2 = new Condition(">","aae042","201801");
//		Condition condition3 = new Condition(">","aae031","201801");
//		list.add(condition1);
//		list.add(condition2);
//		list.add(condition3);
//		String sqlCondtion = Condition.toSqlConditionString(list);
//		System.out.println(sqlCondtion);
//	}

}
